package edu.gatech.wms.views;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.support.v4.app.ListFragment;
import android.util.SparseIntArray;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import edu.gatech.wms.controllers.Login;
import edu.gatech.wms.controllers.UserManager;

public class AdminFragment extends ListFragment
{
	private SparseIntArray pos;
	
	@Override
	public void onResume()
	{
		super.onResume();
		List<Integer> ids = UserManager.getAllUsers();
		List<String> names = new ArrayList<String>();
		pos = new SparseIntArray();
		
		for(int id : ids)
		{
			pos.put(names.size(), id);
			String t = UserManager.getUserFullName(id) + ", " + UserManager.getUserContact(id);
			t += UserManager.getAdmin(id) ? ", admin" : "";
			t += UserManager.getLockedStatus(id) ? ", locked" : "";
			names.add(t);
		}
		
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, names);
		setListAdapter(adapter);
	}

	@Override
	public void onListItemClick(ListView l, View v, int position, long id)
	{
		Intent intent = new Intent(getActivity(), UserDetailsActivity.class);
		intent.putExtra(Login.USER_KEY, pos.get(position));
		getActivity().startActivityForResult(intent, 1);
	}
}
